package com.android.test.FPS;

import android.util.Log;

public class FPSHandler {
	private float FPS;
	private int timeLog = 5;
	private long startTime;
	private long drawTime;
	private int count;
	private int timeLogMilisecon;
	public FPSHandler(int pTimeLog) {
		timeLog = pTimeLog;
		timeLogMilisecon = timeLog * 1000;
		init();
	}
	
	public FPSHandler() {
		this(5);
	}
	
	private void init() {
		startTime = System.currentTimeMillis();
		drawTime = startTime;
		count = 0;
	}
	
	
    public void setFPS() {
    	count ++;
    	long thisTime = System.currentTimeMillis();
    	drawTime = thisTime - startTime;
    	if (drawTime >= timeLogMilisecon) {
    		FPS = count / (timeLog  * 1f);
    		printFPS();
    		count = 0;
    		startTime = thisTime;
    	}
    }
    
    
    public void printFPS() {
    	Log.i("tuanlm","------------------> FPS : " + FPS);
    }
}
